/**
 * Created by song on 2017/9/24.
 */
function onDocumentMouseDown( event ) {

    event.preventDefault();


    //     用一个新的原点和方向向量来更新射线（ray）。
    // .setFromCamera ( coords, camera )
    // 1
    // coords — 鼠标的二维坐标，在归一化的设备坐标(NDC)中，也就是X 和 Y 分量应该介于 -1 和 1 之间。
    // camera — 射线起点处的相机，即把射线起点设置在该相机位置处。
    raycaster.setFromCamera( mouse, camera );   //射线捕捉
    var intersects = raycaster.intersectObjects([go_yangtai]);
    // console.log("intersects------",intersects)
    if ( intersects.length > 0 && time == 2) {
        changeScene();
    }

    isUserInteracting = true;
    is_click = true;
    onPointerDownPointerX = event.clientX;
    console.log("onPointerDownPointerX------",onPointerDownPointerX)
    onPointerDownPointerY = event.clientY;
    onPointerDownLon = lon;
    onPointerDownLat = lat;

}

function onDocumentTouchDown(event) {
    event.preventDefault();

    isUserInteracting = true;
    onPointerDownPointerX = event.touches[ 0 ].pageX ;
    onPointerDownPointerY = event.touches[ 0 ].pageY;


    onPointerDownLon = lon;
    onPointerDownLat = lat;
}


function onDocumentMouseMove( event ) {
  //  console.log("tex", sushe);
    //屏幕位置转换到3D世界坐标系
    mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

    // console.log("mouse.x-----",mouse.x)
    // console.log("mouse.y-----",mouse.y)
    if ( isUserInteracting === true ) {
        // 根据用户鼠标移动的距离 分别计算x/y轴旋转的角度
        // 0.1是自己定义的参数可以改
        // 每次都要加上之前的弧度
        lon = ( onPointerDownPointerX - event.clientX ) * 0.1 + onPointerDownLon;
        lat = ( event.clientY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
    }
}

//手机控制适配
function onDocumentTouchMove( event ) {

    if ( isUserInteracting === true ) {
        lon = ( onPointerDownPointerX - event.touches[ 0 ].pageX  ) * 0.1 + onPointerDownLon;
        lat = ( event.touches[ 0 ].pageY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
    }
}

function onDocumentMouseUp( event ) {
    isUserInteracting = false;
}

function onDocumentMouseWheel( event ) {
    camera.fov += event.deltaY * 0.05;
    camera.updateProjectionMatrix();
}